<template>
  <div class="_wz_associatedInformation">
    <Card dis-hover :bordered="true">
      <p slot="title">运输车辆关联列表</p>
      <div style="height: 100%;" ref="tableH">
        <Table stripe highlight-row :loading="loading" border :columns="columns" :data="data" :height="tableHeight"></Table>
      </div>
    </Card>

    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>
  export default {
    props: ["selectData"],
    data() {
      return {
        spinShow:false,//本页加载
        data: [],
        loading: true,
        tableHeight: 400,
        columns: [
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '车牌号', minWidth: 120, key: 'carPlateNo'},
          {title: '车架号', minWidth: 190, key: 'vehicleFrameNo'},
          {title: '车主业户', minWidth: 120, key: 'vehicleOwnerName'},
          {title: '车主联系电话', minWidth: 140, key: 'vehicleOwnerPhone'},
          {title: '车辆类型', minWidth: 150, key: 'vehicleType'},
          {title: '运输企业', minWidth: 260, key: 'vehicleDeptName'},
          {
            title: '操作', fixed: 'right', width: 140,
            render: (h, params) => {
              return h('Button', {
                props: {type: 'info', size: "small"},
                style: {"margin": "0px 5px 0 0"},
                on: {
                  click: () => {
                    this.unbundle(params.row)
                  }
                }
              }, "解绑");
            }
          },
        ],
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;

      that.tableLoadData();
      that.$nextTick(function () {
        that.tableHeight = that.$refs.tableH.offsetHeight;
        window.onresize = ()=> {
          that.tableHeight = that.$refs.tableH.offsetHeight;
        };
      })
    },
    methods: {//执行的方法

      //加载表格数据
      tableLoadData() {
        let that = this;
        that.loading = true;//加载
        that.axios.post(that.apiUrl.webApi + "/management/vehicle/binding/driverVehicle/list", {driverUuid: that.selectData.uuid}).then(res => {
          that.loading = false;
          if (!!res) {
            that.data = res.data.data;
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
      //解绑
      unbundle(data) {
        let that = this;
        that.$Modal.confirm({
          title: '解绑提醒',
          content: '确定要解绑选中的记录？',
          onOk: () => {
            that.spinShow = true;
            that.axios.post(that.apiUrl.webApi + "/management/vehicle/binding/unbind/trailerVehicle", {uuid: data.uuid}).then(res => {
              that.spinShow = false;
              if (!!res) {
                that.$Message.success("解绑成功");
                that.tableLoadData()
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //点击取消
          }
        });
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态
      window.onresize = null;
    }
  }
</script>
<style lang="less">
  ._wz_associatedInformation {


  }

</style>
